package com.xieli.invitesdk.ui

import android.app.Dialog
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.DialogFragment
import com.xieli.invitesdk.R
import com.xieli.invitesdk.databinding.ShareDialogLayoutBinding
/**
 * @Auther sr
 * @Date 2023/9
 * @Description 转发邀请弹窗
 */
class ShareDialog(val click:(left:Boolean)->Unit) : DialogFragment()  {

    private lateinit var databinding: ShareDialogLayoutBinding

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val dialog = super.onCreateDialog(savedInstanceState)
        // 设置对话框样式，使其位于底部
        dialog.window?.apply {
            setBackgroundDrawableResource(android.R.color.transparent)
            setGravity(Gravity.BOTTOM)

        }
        return dialog
    }

    override fun onStart() {
        super.onStart()
        dialog?.window?.apply {
            attributes?.windowAnimations = R.style.DialogAnimation
            setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
        }
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        databinding = DataBindingUtil.inflate(inflater, R.layout.share_dialog_layout, container, false)
        //微信分享好友回调
        databinding.btnWxshare.setOnClickListener{
            click.invoke(true)
            dismiss()
        }
        //复制到剪切板回调
        databinding.btnCopy.setOnClickListener{
            click.invoke(false)
            dismiss()
        }
        //关闭弹窗
        databinding.btnCancel.setOnClickListener{
            dismiss()
        }

        return databinding.root
    }
}